package com.example.mobile2021606129ly0413;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


    private Button butClo;
    private Button butAdd;
    private Button butGoodCho;
    private Button butCusCho;
    private TextView tvGood;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initview();
        butClo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog dialog;
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setTitle("普通对话框");
                builder.setMessage("是否确定退出应用：");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        MainActivity.this.finish();
                    }
                });
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                dialog = builder.create();
                dialog.show();
            }
        });
    }
//        butCusCho.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//
//                AlertDialog dialog;
//                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
//                builder.setTitle("供应商选择");
//                final String items[] = {"新星汽车配件", "枫叶汽车配件", "天辉汽车配件", "细末汽车配件"};
//                builder.setSingleChoiceItems(items, new DialogInterface.OnClickListener() {
//                    public void onClick(DialogInterface dialog, int which) {
//                        String item = items[which];
//
//                        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//                            @Override
//                            public void onClick(DialogInterface dialog, int which) {
//                                dialog.dismiss();
//                                tvGood.setText(item);
//                            }
//                        });
//
//                        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
//                            @Override
//                            public void onClick(DialogInterface dialog, int which) {
//                                dialog.dismiss();
//                            }
//                        });
//
//                        dialog = builder.create();
//                        dialog.show();
//
//                    }
//                });
//            }
//        });

            private void initview() {
                butClo = (Button) findViewById(R.id.but_clo);
                butAdd = (Button) findViewById(R.id.but_add);
                butGoodCho = (Button) findViewById(R.id.but_good_cho);
                butCusCho = (Button) findViewById(R.id.but_cus_cho);
                tvGood = (TextView) findViewById(R.id.tv_good);
            }
        }






